package com.ewanghuiju.app.ui.pintuan.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.androidkun.xtablayout.XTabLayout;
import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.SimpleActivity;
import com.ewanghuiju.app.ui.main.adapter.MyPagerAdapter;
import com.ewanghuiju.app.ui.my.activity.ShouyiCenterActivity;
import com.ewanghuiju.app.ui.pintuan.fragment.PintuanOrderListFragment;
import com.ewanghuiju.app.util.StartActivityUtil;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.gyf.immersionbar.ImmersionBar;

import java.util.ArrayList;
import java.util.List;

import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 转售订单列表
 * @time 2020/2/19
 */
public class PintuanOrderListActivity extends SimpleActivity {
    @BindView(R.id.viewpage)
    ViewPager viewpage;
    //    @BindView(R.id.commonTabLayout)
//    CommonTabLayout commonTabLayout;
    @BindView(R.id.xtabLayout)
    XTabLayout xtabLayout;
    @BindView(R.id.tv_title_right)
    TextView tvTitleRight;

//    private ArrayList<CustomTabEntity> mTabEntities = new ArrayList<>();

    private List<Fragment> fragmentList;
    //    private String[] list_Title = {"全部订单", "正在拼团", "拼团成功", "拼团失败"};
    private String[] list_Title = {"全部", "拼团中", "已成团", "待发货", "待收货", "已完成", "已失败"};

    private List<String> strList;

    @Override
    protected int getLayout() {
        return R.layout.activity_pintuan_orderlist;
    }

    @Override
    protected void initEventAndData() {
        tvTitleRight.setVisibility(View.VISIBLE);
        tvTitleRight.setTextColor(ContextCompat.getColor(mContext, R.color.color_666));
        tvTitleRight.setText(getString(R.string.pintuan_order_shouyi));
        initFragment();
    }

    @Override
    protected int getTitleIntText() {
        return R.string.pintuan_order_title;
    }

    private void initFragment() {
        fragmentList = new ArrayList<>();
        strList = new ArrayList<>();
        for (int i = 0; i < list_Title.length; i++) {
//            mTabEntities.add(new TabEntity(list_Title[i], R.mipmap.icon_selected_tab, 0));
            strList.add(list_Title[i]);
            PintuanOrderListFragment pintuanOrderListFragment = new PintuanOrderListFragment();
            Bundle bundle = new Bundle();
            bundle.putInt(Constants.PINTUANORDER_TYPE, i);
            pintuanOrderListFragment.setArguments(bundle);
            fragmentList.add(pintuanOrderListFragment);
        }
//        PintuanOrderTopTagAdapter  TODO  优化
        viewpage.setAdapter(new MyPagerAdapter(getSupportFragmentManager(), 0, fragmentList, strList));
//        commonTabLayout.setTabData(list_Title);
//        commonTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
//            @Override
//            public void onTabSelect(int position) {
//                viewpage.setCurrentItem(position);
//            }
//
//            @Override
//            public void onTabReselect(int position) {
//            }
//        });
//
//        viewpage.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
//            @Override
//            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
//
//            }
//
//            @Override
//            public void onPageSelected(int position) {
//                commonTabLayout.setCurrentTab(position);
//            }
//
//            @Override
//            public void onPageScrollStateChanged(int state) {
//
//            }
//        });
        int currentPage = getIntent().getIntExtra(Constants.PINTUANORDER_TYPE, 0);
        viewpage.setCurrentItem(currentPage);

        xtabLayout.setupWithViewPager(viewpage);
    }


    @OnClick({R.id.tv_title_right})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_title_right:
                //拼团收益
                new StartActivityUtil(mContext, ShouyiCenterActivity.class).startActivity(true);
                break;
            default:
                break;
        }
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        ImmersionBar.with(this)
                .titleBar(mToolbar, true)
                .statusBarDarkFont(true)
                .init();
    }

}
